﻿using System;

namespace Vibstudio.X4NET
{
    [Serializable]
    public class OperationResult
    {
        public bool IsPerformed { get; set; }

        public string Message { get; set; }

        protected OperationResult(bool isPerformed, string message)
        {
            IsPerformed = isPerformed;
            Message = message;
        }

        public static OperationResult CreateSuccess()
        {
            return new OperationResult(true, string.Empty);
        }

        public static OperationResult CreateFailure(string message)
        {
            return new OperationResult(false, message);
        }
    }

    [Serializable]
    public class OperationResult<T> : OperationResult
    {
        public static OperationResult<T> Default(T output)
        {
            return new OperationResult<T>(true, "", output);
        }

        public static OperationResult<T> CreateSuccess(T output)
        {
            return new OperationResult<T>(true, string.Empty, output);
        }

        public static OperationResult<T> CreateSuccess(T output, string message)
        {
            return new OperationResult<T>(true, message, output);
        }

        public static OperationResult<T> CreateFailure(string failureMessage, T output = default(T))
        {
            if (ReferenceEquals(output, null)) output = default(T);
            return new OperationResult<T>(false, failureMessage, output);
        }

        public T Output { get; set; }

        protected OperationResult(bool isPerformed, string message, T output)
            : base(isPerformed, message)
        {
            Output = output;
        }
    }
}